package com.peng.controller;

import com.github.pagehelper.PageInfo;
import com.peng.Repo.PageStatic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@RestController
public class AdminUserConsumerController {
    @Autowired
    private RestTemplate restTemplate;

    //private static final String REST_URL_PREFIX = "http://localhost:8011";
    //通过Ribbon 请求时 应该是个变量 ，通过服务名去访问
    private static final String REST_URL_PREFIX = "http://SPRINGCLOUD-PROVIDER-LOGIN";

    @GetMapping("/consumer/admin/user")
    public PageInfo getUser(@RequestParam(name = "username", defaultValue = "") String username,
                            @RequestParam(name = "status", defaultValue = "0") Integer status,
                            @RequestParam(name = "Level", defaultValue = "0") Integer Level,
                            @RequestParam(name = "page", defaultValue = PageStatic.page) Integer page,
                            @RequestParam(name = "size", defaultValue = PageStatic.size) Integer size) {
        Map<String, Object> map = new HashMap<>();
        map.put("username", username);
        map.put("status", status);
        map.put("Level", Level);
        map.put("page", page);
        map.put("size", size);
        return restTemplate.getForObject(REST_URL_PREFIX + "/admin/user", PageInfo.class, map);
    }
}
